﻿using System;

class ReverseWords
{
    static void Main()
    {
        string text = "C# is not C++, not PHP and not Delphi!";
        string[] reversed = text.Split(' ');
        char[] separators = new char[reversed.Length];

        // Checking the separator position
        for (int i = 0; i < reversed.Length; i++)
        {
            int revStrLen = reversed[i].Length;

            switch (reversed[i][revStrLen - 1])
            {
                case '.':
                    separators[i] = '.';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case ',':
                    separators[i] = ',';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case ':':
                    separators[i] = ':';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case ';':
                    separators[i] = ';';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case '!':
                    separators[i] = '!';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case '?':
                    separators[i] = '?';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                case '\'':
                    separators[i] = '\'';
                    reversed[i] = reversed[i].Substring(0, revStrLen - 1);
                    break;
                default: separators[i] = ' ';
                    break;
            }
        }

        // Reversing the words
        for (int i = reversed.Length - 1; i > 0; i--)
        {
            Console.Write(reversed[i]);

            // Only if there is a separator we add it to the string with the white space
            if (separators[separators.Length - 1 - i] != ' ')
            {
                Console.Write(separators[separators.Length - 1 - i] + " ");
            }
            else
            {
                Console.Write(" ");
            }            
        }

        // Printing the last word without whitespace after it.
        Console.WriteLine(reversed[0] + separators[separators.Length - 1]);
    }
}
